package com.item.manager;

import com.google.common.collect.Range;
import org.immutables.value.Value;

import java.util.Random;

/**
 * Contains value in some interval.
 *
 * @author Blind
 */
@Value.Immutable
public abstract class RangeAttribute implements Attribute {

    public abstract Range<Integer> value();

    /**
     * This calculates random only ones, after returns cached value.
     */
    @Value.Lazy
    public int defPoint() {
        return value().lowerEndpoint() + (new Random().nextInt(value().upperEndpoint() - value().lowerEndpoint()));
    }

    @Value.Lazy
    public int asInt() {
        return defPoint();
    }
}
